package zhongbo.java.air.dictionary.web.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zhongbo.java.air.common.vo.PageVo;
import zhongbo.java.air.common.vo.ResultVo;
import zhongbo.java.air.dictionary.model.entities.AirCraft;
import zhongbo.java.air.dictionary.service.IAirCraftService;

/**
 * 说明：
 * 飞机基础信息操作的相关接口
 *
 * @author 钟波dellNotebook
 * @since 2025年03月31日 星期一 08:30:28
 */
@Api(tags = "飞机相关接口")
@RestController
@RequestMapping("/aircraft")
public class AirCraftController {

    @Autowired
    private IAirCraftService airCraftService;

    /**
     * 保存飞机信息到数据库
     *
     * @param airCraft 飞机信息
     * @return 返回保存的飞机信息
     */
    @PostMapping("/add")
    @ApiOperation("保存飞机信息")
    public ResultVo<AirCraft> saveAirCraft(@RequestBody AirCraft airCraft) {
        AirCraft resAirCraft = airCraftService.saveAirCraft(airCraft);
        return ResultVo.ok(resAirCraft);
    }

    /**
     * 根据飞机id删除飞机信息
     *
     * @param id 飞机id
     * @return 被删除的飞机id
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除飞机信息")
    public ResultVo<String> delAirCraft(String id) {
        String deletedId = airCraftService.delAirCraft(id);
        return ResultVo.ok(deletedId);
    }

    /**
     * 修改飞机信息
     *
     * @param airCraft 前端传递过来的修改信息
     * @return 修改后的信息
     */
    @PutMapping("/modify")
    @ApiOperation("修改飞机信息")
    public ResultVo<AirCraft> modifyAirCraft(@RequestBody AirCraft airCraft) {
        AirCraft newAircraft = airCraftService.modifyAirCraft(airCraft);
        return ResultVo.ok(newAircraft);
    }

    /**
     * 根据飞机id查询飞机信息
     *
     * @param id 飞机id
     * @return 飞机信息
     */
    @GetMapping("/query")
    @ApiOperation("根据飞机id查询飞机信息")
    public ResultVo<AirCraft> queryAirCraft(String id) {
        AirCraft airCraft = airCraftService.queryById(id);
        return ResultVo.ok(airCraft);
    }

    /**
     * 分页查询飞机信息
     *
     * @param pageNumber   页码
     * @param pageSize     每页记录数
     * @param airline      所属航司
     * @param aircraftType 飞机类型
     * @param status       状态
     * @param orderBy      排序字段
     * @param orderType    排序类型，true升序 false降序 默认降序
     * @return 飞机分页信息
     */
    @GetMapping("/page")
    @ApiOperation("分页查询飞机信息")
    public ResultVo<PageVo<AirCraft>> pageAirCraft(
            @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
            @RequestParam(value = "airline", required = false) String airline,
            @RequestParam(value = "aircraftType", required = false) String aircraftType,
            @RequestParam(value = "status", required = false) String status,
            @RequestParam(value = "orderBy", required = false) String orderBy,
            @RequestParam(value = "orderType", required = false, defaultValue = "false") Boolean orderType) {
        PageVo<AirCraft> airCraftPageVo = airCraftService.pageAircraft(pageNumber, pageSize, airline,
                aircraftType, status, orderBy, orderType);
        return ResultVo.ok(airCraftPageVo);
    }
}
